package com.example.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {
    public MyService() {
    }

    @Override
    public void onCreate() {//创建（只执行一次
        super.onCreate();
        Log.d("myservice", "oncreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {//启动
        Log.d("myservice", "onstart");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {//绑定（这里得返回一个Binder给外面，这样才能给外面调用方法
        Log.d("myservice", "onbind");
        return new MyBinder();
    }

    @Override
    public void onDestroy() {//摧毁
        super.onDestroy();
        Log.d("myservice", "ondestroy");
    }

    @Override
    public boolean onUnbind(Intent intent) {//解绑
        Log.d("myservice", "onunbind");
        return super.onUnbind(intent);
    }

    public class MyBinder extends Binder {
        public void xxx() {
            Log.d("myservice", "xxx");
        }
    }
}